using System;
using System.Collections.Generic;
using System.Text;

namespace Wrath.Xml.Objects
{
    public class ControlTabTarget : IElementContainer
    {
        private string next;

        public string Next
        {
            get { return next; }
            set { next = value; }
        }

        private string previous;

        public string Previous
        {
            get { return previous; }
            set { previous = value; }
        }	
	
        public ControlTabTarget(Element element)
        {
            sourceElement = element;

            Element subElement = element.FindFirstElement("next", false);
            if (subElement != null)
            {
                next = subElement.Value.Substring(0);
            }

            subElement = element.FindFirstElement("prev", false);
            if (subElement != null)
            {
                previous = subElement.Value.Substring(0);
            }

        }

        #region IElementContainer Members

        private Element sourceElement;
        public Element SourceElement
        {
            get { return sourceElement; }
        }

        public void Commit()
        {
            sourceElement = new Element("tabtarget");

            if (!String.IsNullOrEmpty(next))
            {
                Element subElement = new Element("next");
                subElement.Value = next;

                sourceElement.ChildElements.Add(subElement);
            }

            if (!String.IsNullOrEmpty(previous))
            {
                Element subElement = new Element("prev");
                subElement.Value = previous;

                sourceElement.ChildElements.Add(subElement);
            }
        }

        #endregion
    }
}
